$(document).ready(function(){
	$(window).load(function(){
		var 
			oPic=$('.pic'),
			oSmallPic=$('.small_pic'),
			oFloat=$('.float_box'),
			oBigPic=$('.big_pic');
		oSmallPic.mouseover(function(){
			oFloat.css('display','block');
			oBigPic.css('display','block');
		}).mouseout(function(){
			oFloat.css('display','none');
			oBigPic.css('display','none');
		}).mousemove(function(e){
			var evt=e||event,
				getPosition=oPic.position(),
				l=evt.clientX-getPosition.left-oFloat.width()/2,
				t=evt.clientY-getPosition.top-oFloat.height()/2;
				if(l<0){
					l=0
				}else if(l>oSmallPic.width()-oFloat.width()){
					l=oSmallPic.width()-oFloat.width()
				}
				if(t<0){
					t=0
				}else if(t>oSmallPic.height()-oFloat.height()){
					t=oSmallPic.height()-oFloat.height()
				}
			oFloat.css({left:l,top:t});
			var 
				oImg=$('.big_pic img')
				disX=l/(oFloat.width()-oSmallPic.width()),
				disY=t/(oFloat.height()-oSmallPic.height()),
				leftM=disX*(oImg.width()-oBigPic.width()),
				topM=disY*(oImg.height()-oBigPic.height());
				oImg.css({left:leftM,top:topM})
			
		})
		
		
	$('.pic_list ul li').mouseover(function(){
		
		var num=$('.pic_list ul li').index($(this));
		var src=$('.pic_list ul li').eq(num).children('img').attr('src');
		$('.small_pic a img').attr('src',src);
		$('.big_pic a img').attr('src',src);
		
	})
	
/*商品评论*/
var num=0;
	$('#prev').click(function(){
		num--;
		if(num<0){
			num=0
		}
		pageMove()
	})
	$('#next').click(function(){
		num++;
		pageMove()
	})
function pageMove(){
	$.ajax({
		url:"http://sclub.jd.com/productpage/p-1643513-s-3-t-3-p-"+num+".html",
		dataType:'jsonp',
		success:function(data){
			console.log(data)
			var arr=data.comments
			for(var i=0;i<arr.length;i++){
				$('.comment_day').eq(i).html('下单'+arr[i].days+'天后评论');
				$('.comment_time').eq(i).html(arr[i].creationTime);
				$('.comment_cont').eq(i).html(arr[i].content);
				$('.feature').eq(i).html(arr[i].productColor);
				$('.user_name img').eq(i).attr('src','http://'+arr[i].userImageUrl);
				$('.user_name p').eq(i).html(arr[i].nickname);
				$('.user_name b').eq(i).html(arr[i].userLevelName);
				$('.grade_star').eq(i).html('');
				for(var j=0;j<arr[i].score;j++){
					
					$('.grade_star').eq(i).append('<i class="iconfont">&#xe611;</i>')
				}
				
		}		

		}
	
	})
}
pageMove()	
	
	
	
	
	
	
	
			
	})
})
